package com.kehutong.common.urlconfig;

import org.coraframework.http.HttpClient;
import org.coraframework.inject.Singleton;
import org.coraframework.json.JSONObject;
import org.coraframework.util.CallBack;
import com.kehutong.common.webchat.XmlUtil;

/**
 * 支付相关配置
 * @author liuzhen
 */
@Singleton
public class PayUrlConfig extends UrlConfig{

	protected PayUrlConfig() {
		super("tencent", "webchat_pay_url");
	}

	/**
	 * post请求，返回xml
	 * @param page
	 * @param client
	 * @return
	 * @throws Exception
	 */
	public JSONObject postXML(String page, CallBack<HttpClient> client) throws Exception {
		final HttpClient httpClient = HttpClient.create(getUrl() + page);
		client.call(httpClient);

		String text = httpClient.post();
		if (httpClient.getResponseCode() != 200) {
			return httpError(httpClient.getResponseCode(), "http状态错误");
		}

		logger.info("{}", text);
		return XmlUtil.xml2JSON(text);
	}
}
